package com.iussoft.demo.jms;


import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;

/**
 * @description: 发布jms服务
 * @author: Hou Dayu
 * @date: Created in 2020/10/27
 */
public class MQRecevicer  {

    public void startJmsServer(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("发布JMS服务！");
                String xbean = "xbean:activemq.xml";
                final BrokerService broker;
                try {
                    broker = BrokerFactory.createBroker(xbean);
                    broker.start();
                    boolean falg = true;
                    // 一直启动不关闭
                    while(true){
                        if(falg) {
                            QueueReceiver receiver = new QueueReceiver();
                            receiver.execute();
                        }
                        Thread.sleep(10*1000);
                        falg=false;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
